//
//  AppDelegate.swift
//  ZkManager
//
//  Created by 笑看风云旦 on 2020/3/22.
//  Copyright © 2020 笑看风云旦. All rights reserved.
//

import Cocoa
import SwiftUI

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    var window: NSWindow!


    func applicationDidFinishLaunching(_ aNotification: Notification) {
        
        
        // 绑定SwiftUI
        let contentView = ConnectView()

        // Create the window and set the content view.
        window = NSWindow(
            contentRect: NSRect(x: 0, y: 0, width: 480, height: 300),
//            styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
            styleMask: [.titled, .closable, .miniaturizable],
            backing: .buffered, defer: false)
        window.center()
        window.setFrameAutosaveName("Main Window")
        window.contentView = NSHostingView(rootView: contentView)
    
        
        //添加自定义按钮
        let titleView = NSHostingView(rootView:
            ZStack {
              Color.clear
            HStack() {
                
                    Spacer(minLength: 75)
                    
                    Button(action: {
                            print("lalala")
                        }, label: {
                            
                            Image("icons8-plus").resizable().frame(width: 15, height: 15, alignment: .center).offset(x:0,y:-15)
                            
                    })
                
                    Spacer(minLength: 550)
                
                    Button(action: {
                                print("lalala")
                            }, label: {
                            Image("icons8-new-post").resizable().frame(width: 15, height: 15, alignment: .center).offset(x:0,y:-15)
                        })
                                
                }
            }
            .padding()
            .edgesIgnoringSafeArea(.all)
        )
        titleView.frame.size = titleView.fittingSize
        
        let titlebarAccessory = NSTitlebarAccessoryViewController()
        titlebarAccessory.view = titleView
//        titlebarAccessory.layoutAttribute = .trailing
        titlebarAccessory.layoutAttribute = .leading
        window.toolbar = .init()
        window.titleVisibility = .hidden
        window.addTitlebarAccessoryViewController(titlebarAccessory)
        
        window.makeKeyAndOrderFront(nil)
    }

    func applicationWillTerminate(_ aNotification: Notification) {
        // Insert code here to tear down your application
    }


}

